﻿using GeekTime.Domain.Abstructions;
using GeekTime.Domain.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace GeekTime.Domain.OrderAggregate
{
    /// <summary>
    /// Order实体
    /// 所有的set设置为private，这样，所有的数据操作，都应该是由实体去负责的而不应该被外部的对象去操作。
    /// 让领域模型符合封闭开放的原则
    /// </summary>
    public class Order:Entity<long>,IAggregateRoot
    {
        public string UserId { get; private set; }
        public string UserName { get; private set; }
        public Address Address { get; private set; }
        public int ItemCount { get; private set; }
        protected Order()
        {

        }
        public Order(string userId,string userName,int itemCount,Address address)
        {
            UserId = userId;
            UserName = userName;
            Address = address;
            ItemCount = itemCount;

            this.AddDomainEvent(new OrderCreatedDomainEvent(this));
        }

        //对于领域模型的操作，都应该是定义我们具有的业务逻辑含义的方法去定义
        /// <summary>
        /// 修改地址
        /// </summary>
        /// <param name="address"></param>
        public void ChangeAddress(Address address)
        {
            //可以加逻辑判断，比如地址的举例是否符合常规等。。。
            Address = address;
            //定义个OrderAddressChangedDomainEvent领域事件
            //this.AddDomainEvent(new OrderAddressChangedDomainEvent(this))
        }
    }
}
